﻿import LuminicBox.Log.ConsolePublisher;
import org.aswing.*;
import org.aswing.plaf.custom.parser.css.CSSDocument;
import org.aswing.plaf.custom.parser.ParserLog;
import org.aswing.plaf.custom.parser.XMLStyleParser;
import org.aswing.plaf.custom.CustomLookAndFeel;
import org.aswing.plaf.winxp.WinXpLookAndFeel;
import org.aswing.table.*;
import LuminicBox.Log.Logger;
import org.aswing.util.Delegate;

class FrameEditor extends JFrame{
	
	private var editor:JTextArea;
	private var logger:JTextArea;
	
	private var loadBtn:JButton;
	
	function FrameEditor(){
		super (_root, true);
		setTitle( "ASwing LookAndFeel CSS Editor");
		
		editor = new JTextArea();
		logger = new JTextArea();
		editor.setPreferredSize(400,530);
		//logger.setPreferredSize(400,130)
		logger.setEditable(false);
		logger.setText("Parser log...")
		
		var editorScrollPane:JScrollPane = new JScrollPane(editor);
		var loggerScrollPane:JScrollPane = new JScrollPane(logger);
				
		var editorPane:JPanel = new JPanel();
		editorPane.append(editorScrollPane);
		
		var loggerPane:JPanel = new JPanel();
		loggerPane.append(loggerScrollPane);	
		
		loadBtn = new JButton("Update LAF");
		loadBtn.addEventListener(JButton.ON_PRESS,updateLAF,this);
		
		var rightPane:JPanel = new JPanel();		
		rightPane.setLayout(new BorderLayout());		
		rightPane.append(editorPane, BorderLayout.NORTH);		
		//rightPane.append(loggerPane, BorderLayout.CENTER);
		rightPane.append(loadBtn,BorderLayout.SOUTH)
		
		getContentPane().append(rightPane, BorderLayout.EAST);
		
		var leftPane:JPanel = new JPanel();	
		leftPane.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
		
		var label:JLabel = new JLabel("mouse over to see tool tip..");
		label.setToolTipText("A label's Tooltip")
		leftPane.append(label);
		
		
		leftPane.append(new JCheckBox("check box"));
		leftPane.append(new JSlider(0,0,100,2));
		leftPane.append(new JRadioButton ("RadioButton");)
		var listData:Array = ["11111111111111",
								"22222222222222222",
								"3333333333333333",
								"44444444444444444"];
		var model1:VectorListModel = new VectorListModel(listData);		
		leftPane.append(new JComboBox(model1));
		var data:Array = [["iiley", 100, true, 23, 33, "the last"],
		  ["I dont know who", -12, false, 13, 33, "the last"],
		  ["A little cute girl", 98765, false, 0, 33, "the last2"],
		  ["Therion1", 99, true, 23, 33, "the last3"],
		  ["Therion2", 99, true, 63, 33, "the last4"],
		  ["Therion3", 99, true, 23, 33, "the last5"],
		  ["Therion4", 99, true, 23, 33, "the last5"]];
		for(var i:Number=0; i<100; i++){
			data.push(["other"+i, i, Math.random()<0.5, 13, 323, i+"last"]);
		}
		var column:Array = ["name", "score", "male", "number", "number", "last"];
		var model2:DefaultTableModel = (new DefaultTableModel()).initWithDataNames(data, column);
		leftPane.append(new JTable(model2));
		
		getContentPane().append(leftPane, BorderLayout.WEST);
		
	}
	
	public function updateLAF():Void{
		LAFEditor.cssText = this.editor.getText();
		LAFEditor.init();
	}
	
	public function setEditorCSS(css:String):Void{
		this.editor.setText(css)
	}
	
	public function setLog(log:String):Void{
		this.logger.setText(log)
	}
}
